package main

import (
	"errors"
	"fmt"
)

func divide(a int, b int) (int, error) {
	if b <= 0 {
		return 0, errors.New("b must > 0")
	}
	return a / b, nil
}

func divide2(a int, b int) (int, error) {
	if b <= 0 {
		return 0, fmt.Errorf("b must > 0")
	}
	return a / b, nil
}

func divide3(a int, b int) (int, error) {
	if b <= 0 {
		return 0, &BusinessError{"BN-001"}
	}
	return a / b, nil
}

// BusinessError custom error type
type BusinessError struct {
	businessNo string
	//err        error
}

//implement interface error
func (b *BusinessError) Error() string {
	panic(fmt.Sprintf("%s produce error", b.businessNo))
}

func NewError() {
	//i, err := divide(1, -1)
	//i, err := divide2(1, -1)
	i, err := divide3(1, -1)
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(i)
	}
}

func main() {
	NewError()
}
